package com.aaa.controller;

import com.aaa.entity.MyReturn;
import com.aaa.entity.Test_plan;
import com.aaa.service.Test_plan_fpaService;
import com.aaa.util.Enum01;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("test_plan_fpa")
public class Test_plan_fpaController extends BaseController{

    @Autowired
    private Test_plan_fpaService FpaPlan;

    MyReturn myReturn=new MyReturn();



    @RequestMapping("toShowFpaPlan.do")
    public String toShowUserPage(){
        return "showFpaPlan";
    }

    /**
    * @Author: WTH
    * @Description: 查询,分页,计算总条数
    * @Date:2022-07-01 10:13
    * @Params:
    */
    @ResponseBody
    @RequestMapping("selectPlanFpa.do")
    public MyReturn selectPlanFpa(Test_plan plan_fpa){
        Page<Test_plan> page=FpaPlan.selectFpaPlan(plan_fpa);
        myReturn.setData(page.getResult());
        super.getSuccessReturn(myReturn);
        myReturn.setCount(page.getTotal());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 新增
    * @Date:2022-07-01 15:05
    * @Params:
    */
    @ResponseBody
    @RequestMapping("addPlanFpa.do")
    public MyReturn addFpaPlan(Test_plan plan_fpa){
        plan_fpa.setCreate_time(new Date());
        plan_fpa.setTest_begin(new Date());
//        plan_fpa.setTest_end();
        Enum01 enum01 = FpaPlan.addFpaPlan(plan_fpa);
        myReturn.setCode(enum01.getCode());
        myReturn.setMsg(enum01.getMsg());
        return myReturn;
    }

    /**
    * @Author: WTH
    * @Description: 删除
    * @Date:2022-07-01 15:49
    * @Params:
    */
    @ResponseBody
    @RequestMapping("deletePlanFpa.do")
    public MyReturn deleteFpaPlan(String id){
        boolean b = FpaPlan.deleteFpaPlan(id);
        if(b){
            return super.getSuccessReturn(myReturn);
        }else{
            return super.getFailReturn(myReturn);
        }
    }

    /**
    * @Author: WTH
    * @Description: 修改
    * @Date:2022-07-01 16:02
    * @Params:
    */
    @ResponseBody
    @RequestMapping("updatePlanFpa.do")
    public MyReturn update(Test_plan plan_fpa){
        plan_fpa.setUpdate_time(new Date());
        Enum01 enum01 = FpaPlan.updateFpaPlan(plan_fpa);
        myReturn.setCode(enum01.getCode());
        myReturn.setMsg(enum01.getMsg());
        return myReturn;
    }
}
